
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package algorithms;
import structure.Variable;
import structure.DataFile;
import java.util.ArrayList;
import java.util.HashMap;
import structure.DataPoint;
import structure.NodeDependency;
import structure.State;
import utilities.StringParse;
import utilities.WriteL1Metric;
/**
 *
 * @author timbo/*
 */

public class MDL {

    public static void richardsFaceWithAGirlsVoice(Variable camel, Variable toe){
        double linkMatrix[][] = new double[camel.getNumberOfStates() +1][toe.getNumberOfStates()+1];

        DataFile df = StringParse.data;
        for (State stCamel : camel.getStates()){    // For all X states
            double countX = 0;
            
            for (State stToe : toe.getStates()){    // For all Y states
                double countXY = 0;
                countX++;
                System.out.println("countX is : " + countX);
                for(DataPoint dp : df.getDataPoints()){
                    if ( dp.getState().getStateNumber() == stToe.getStateNumber()
                      //&& dp.getState().getStateNumber() == stCamel.getStateNumber()
                      && dp.getVariable()== toe){
                        countXY++;
                        System.out.println("RAH!!! " + countXY);
                    }
                }
                linkMatrix[stCamel.getStateNumber()-1][stToe.getStateNumber()-1] = countXY/countX;
                System.out.println("Link matrix edited");
                //count = count / df.getNumberOfDataPoints();
                //System.out.println("Variable:" + " State:" + stToe + " Prior Prob:" + count);
            }
        }
        System.out.println("link matrix between nodes " + camel.getId() + " aaaaand " + toe.getId());
                System.out.println("link Matrix (0)(0): " + linkMatrix[0][0]);
                System.out.println("link Matrix (0)(1): " + linkMatrix[0][1]);
                System.out.println("link Matrix (1)(0): " + linkMatrix[1][0]);
                System.out.println("link Matrix (1)(1): " + linkMatrix[1][1]);
    }

    public static void richardsAttempt(){
        DataFile df = StringParse.data;
        for (Variable blah : df.getVariables()){    // For each variable
            if (blah.isRoot()){                     // ... that is root
                for(State st : blah.getStates()){   // For each state
                    double count = 0;
                    for(DataPoint dp : df.getDataPoints()){
                        if (dp.getState().getStateNumber() == st.getStateNumber() && dp.getVariable()==blah){
                            count++;
                            System.out.println("RAH!!! " + count);
                        }
                    }
                 count = count / df.getNumberOfDataPoints();
                 System.out.println("Variable:" + blah + " State:" + st + " Prior Prob:" + count);
                 }
            }

        }

    }

        public double CalcPP(Variable a){

        /*This is the conditional probability of the node given its parents. It is a two dimensional real array with one row
        *for each state of the child node, and one column for each of the possible combinations of states of its parents.
        *Each column will sum to 1.
        */
           // DataFile DF;
           int numberOfStatesA = a.getNumberOfStates();
           double matrixa[] = new double[numberOfStatesA];
//           for (int i=0,i<(numberOfStatesA), i++){
  //             matrixa[i]
           
            double result=0;

            return result;
    }

        public double CalcPP(){
            double result =0;

            return result;


         /*
         * MDLScore/ = ModelSize - ModelAccuracy
         *
         * MDL(B|D) = |B| (log2N)/2 - log2(P(D|B)
         */


        //    int i;
            //double ModelSize, ModelAccuracy,result=0;

            //ModelSize i.e. |B| (log2N)/2
            //ModelSize = ((Math.log(DF.getNumberOfDataPoints())) / Math.log(2.0))/2;

            //ModelAccuracy


     }


}
